
/*$().ready(function() {
	validateRule();
});
$.validator.setDefaults({
	submitHandler : function() {
		save();
	}
});

function onTypeChange() {
	validateRule();
}*/

function save() {
    /*if (($("#liansuoId").val() == '' || $("#liansuoId").val() == undefined || $("#liansuoId").val() == 0) && ($("#teamId").val() == '' || $("#teamId").val() == undefined)) {
        layer.alert("请选择门店!", {icon: 5});
        return false;
    }*/
    // if(!$("#type").val() || $("#type").val()==0){
    // 	layer.alert("请选择类型!", {icon: 5});
    // 	return false;
    // }

    $.ajax({
        cache : true,
        type : "POST",
        url : "/reservationProductCategory/manage/save",
        data : $('#categoryAddForm').serialize(),// 你的formid
        async : false,
        error : function(request) {
            parent.layer.alert("Connection error");
        },
        success : function(data) {
            if (data.code == 0) {
                parent.layer.msg("操作成功");
                parent.reLoad();
                var index = parent.layer.getFrameIndex(window.name); // 获取窗口索引
                parent.layer.close(index);

            } else {
                if (data.msg) {
                    parent.layer.alert(data.msg)
                }else {
                    window.location.href = "/";
                }
            }

        }
    });

}
/*function validateRule() {
	var icon = "<i class='fa fa-times-circle'></i> ";
	var isComp = $('#type').val() == '1';
	$("#categoryAddForm").validate({
		rules : {
			name : {
				required : true,
				remote :{
					url: "/centre/manage/checkName",
					type : "POST", // 数据发送方式
					dataType : "JSON", // 接受数据格式
					data : { // 要传递的数据
						name : function() {
							return $("#name").val();
						}
					}
				}
			},
			shortName : {
				required : true
			},
		},
		messages : {
			name : {
				required : icon + "商户名称不能为空",
				remote : icon + "商户名称已经存在"
			},
			shortName : {
				required : icon + "商户简称不能为空"
			}
		}
	})
}*/

function onThumbBlur() {
    var url = $.trim($('#thumb').val());
    if (url) {
        if (url.indexOf("http") >= 0 || url.indexOf("https") >= 0) {
            $('#categoryAddthumbImg').attr('src', url);
        }else {
            var prefix = "http://pic.jinzhishenghuo.com";
            $('#categoryAddthumbImg').attr('src', prefix + url);
        }
    }
}

function getCentreNmae() {
    $("#centreName").val($("#centreId option:checked").text());
}


/**
 * 选择图片页面
 * @param inputId
 * @param imgId
 */
function onSelectImgBtnClick(inputId, imgId) {
    layer.open({
        id:'selectImg',
        type : 2,
        title : '选择图片',
        maxmin : true,
        shadeClose : false,
        area : [ '60%', '70%' ],
        content : '/platform/config/selectImg/' + inputId +"/"+ imgId // iframe的url
    });
}

/**
 * 加载图片URL
 * @param inputId
 * @param imgId
 * @param url
 */
function loadImgUrl(inputId, imgId, url) {
    $('#'+inputId +'').val(url);
    $('#'+imgId +'').attr('src', url);
}